package homework.day305;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class EmpManager {
	
	static {
       try {
    	   Class.forName("oracle.jdbc.driver.OracleDriver");
       }catch(ClassNotFoundException e){
    	   e.printStackTrace();
       }
	}

	public static void main(String[] args) throws SQLException {
		
		new EmpManager().printEmployee("al", 4000);
		System.out.println("\n");
		new EmpManager().printEmployee("AL", 5000);
	}
	
	public void printEmployee(String name, int salary) throws SQLException {
		
		String dburl = "jdbc:oracle:thin:@localhost:1521:xe";
		Connection conn = DriverManager.getConnection(dburl, "hr", "hr");
		
		PreparedStatement pstmt = conn.prepareStatement("SELECT"
					+ "\nemployee_id, first_name, salary"
					+ "\nFROM employees"
					+ "\nWHERE LOWER(first_name) LIKE ? AND salary >= ?");
		
		pstmt.setString(1, "%" + name.toLowerCase() + "%");
		pstmt.setInt(2, salary);
		
		ResultSet rs = pstmt.executeQuery();
		while(rs.next()) {
			System.out.println(rs.getInt(1) + "\t" + rs.getString(2) + "\t" + rs.getInt(3));
		}
		conn.close();
		pstmt.close();
		rs.close();
	}

}
